package com.panfeng.xcloud.common.security.config;

import com.panfeng.xcloud.common.core.utils.SpringContextUtil;
import com.panfeng.xcloud.common.security.interceptor.AuthInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 *
 * 核心配置类
 *
 * @author xiaobo
 * @version 1.0
 * @since 2018-12-28
 */
@Configuration
@Slf4j
public class CoreConfig {

	@Bean
	@ConditionalOnMissingBean(SpringContextUtil.class)
	public SpringContextUtil springContextUtil() {
		return new SpringContextUtil();
	}

	@Bean
	@ConditionalOnMissingBean(HandlerInterceptor.class)
	@ConditionalOnProperty(prefix = "auth.interceptor", name = "enable", havingValue = "true")
	public AuthInterceptor tokenInterceptor() {
		log.info(">>>>初始化 AuthInterceptor <<<");
		return new AuthInterceptor();
	}
}
